using System;

namespace codeparser.net
{
    /// <summary>
    /// Represents the configuration for a single tag.
    /// </summary>
    public class TagConfiguration
    {
        private string _tag;
        private string _replacement;
        private string _alternativeReplacement;
        private bool _parseContent;
        private string _contentHighlighter;
        private bool _isSingleTag;

        /// <summary>
        /// Gets  a value indicating whether this instance is a single tag.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is a single tag; otherwise, <c>false</c>.
        /// </value>
        public bool IsSingleTag
        {
            get
            {
                return this._isSingleTag;
            }
        }

        /// <summary>
        /// Gets or sets the tag.
        /// </summary>
        /// <value>The tag.</value>
        public string Tag
        {
            get
            {
                return this._tag;
            }

            set
            {
                this._tag = value;
            }
        }

        /// <summary>
        /// Gets or sets the replacement.
        /// </summary>
        /// <value>The replacement.</value>
        public string Replacement
        {
            get
            {
                return this._replacement;
            }

            set
            {
                this._replacement = value;
            }
        }

        /// <summary>
        /// Gets or sets the alternative replacement.
        /// </summary>
        /// <value>The alternative replacement.</value>
        public string AlternativeReplacement
        {
            get
            {
                return this._alternativeReplacement;
            }

            set
            {
                this._alternativeReplacement = value;
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether the content of this tag shall be parsed.
        /// </summary>
        /// <value><c>true</c> if the content of this tag shall be parsed; otherwise, <c>false</c>.</value>
        public bool ParseContent
        {
            get
            {
                return this._parseContent;
            }

            set
            {
                this._parseContent = value;
            }
        }

        /// <summary>
        /// Gets or sets the language for content highlighting.
        /// </summary>
        /// <value>The language for content highlighting.</value>
        public string ContentHighlighter
        {
            get
            {
                return this._contentHighlighter;
            }

            set
            {
                this._contentHighlighter = value;
            }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="TagConfiguration"></see> class.
        /// </summary>
        /// <param name="tag">The tag.</param>
        /// <param name="replacement">The replacement.</param>
        public TagConfiguration(string tag, string replacement)
            : this(tag, replacement, null, true)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="TagConfiguration"></see> class.
        /// </summary>
        /// <param name="tag">The tag.</param>
        /// <param name="alternativeReplacement">The alternative replacement.</param>
        /// <param name="replacement">The replacement.</param>
        public TagConfiguration(string tag, string replacement, string alternativeReplacement)
            : this(tag, replacement, alternativeReplacement, true)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="TagConfiguration"/> class.
        /// </summary>
        /// <param name="tag">The tag.</param>
        /// <param name="replacement">The replacement.</param>
        /// <param name="parseContent">If set to <c>true</c>, the content of this tag shall be parsed.</param>
        public TagConfiguration(string tag, string replacement, bool parseContent)
            : this(tag, replacement, null, parseContent, null)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="TagConfiguration"/> class.
        /// </summary>
        /// <param name="tag">The tag.</param>
        /// <param name="replacement">The replacement.</param>
        /// <param name="alternativeReplacement">The alternative replacement.</param>
        /// <param name="parseContent">If set to <c>true</c>, the content of this tag shall be parsed.</param>
        public TagConfiguration(string tag, string replacement, string alternativeReplacement, bool parseContent)
            : this(tag, replacement, alternativeReplacement, parseContent, null)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="TagConfiguration"/> class.
        /// </summary>
        /// <param name="tag">The tag.</param>
        /// <param name="replacement">The replacement.</param>
        /// <param name="alternativeReplacement">The alternative replacement.</param>
        /// <param name="parseContent">If set to <c>true</c>, the content of this tag shall be parsed.</param>
        /// <param name="contentHighlighter">The language for content highlighting.</param>
        public TagConfiguration(string tag, string replacement, string alternativeReplacement, bool parseContent, string contentHighlighter)
        {
            this._tag = tag;
            this._replacement = replacement;
            this._alternativeReplacement = alternativeReplacement;
            this._parseContent = parseContent;
            this._contentHighlighter = contentHighlighter;

            // If there is a '{0}' in the replacement string the tag cannot be a single tag.
            if (replacement.Contains("{0}"))
            {
                this._isSingleTag = false;
            }
            else
            {
                this._isSingleTag = true;
            }
        }
    }
}